<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2014/10/9
 * Time: 11:32
 * 网点员工排期表
 */
class NetworkStaffSchedule extends CActiveRecord
{
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    public function tableName()
    {
        return 'network_staff_schedule';
    }
    /**
     * 检查是否设置
     */
    public function check($staff_id, $week)
    {
        $criteria = new CDbCriteria();
        $criteria->addColumnCondition(array('staff_id' => intval($staff_id)));
        $criteria->addColumnCondition(array('week' => intval($week)));
        return $this->find($criteria);
    }
    /**
     * 得到员工排期
     */
    public function getByStaff($staff_id)
    {
        $data = $this->findAll('staff_id='.$staff_id);;
        if ($data) 
        {
            $result = array();
            foreach ($data as $key => $val) 
            {
                $week = $val['week'];
                $result[$week] = $val;
            }
            for($i=1; $i<=7; $i++) 
            {
                if (!isset($result[$i])) 
                {
                    $result[$i] = array();
                }
            }
            return $result;
        }
        return $data;
    }
}